n= input ()
 
if len(str(n)) != 4:
    print(0)
else:
    prime = False
    for length in range(4, 0, -1):
        if prime:
            break
        for q in range(4 - length + 1):
            e = int(str(n)[q:q+length])
            if e < 2:
                continue
            for l in range(2, int(e**0.5) + 1):
                if e % l == 0:
                    break
            else:
                print(e)
                prime = True
                break
    if not prime:
        print(0)
